package jscinttools.scint.emissionspectrum;

import hep.aida.IDataPointSet;

import jhplot.P1D;
import jhplot.P0D;

import java.lang.System;
import java.io.PrintStream;

/**
 *  Convert Emission Spectra Energy Scale from cm-1 to nm
 *
 *@author     Marc-Antoine Verdier
 *@created    14 avril 2011
 */
public class CmInvToNm implements EnergyScaleConverter
{
	/**
	 *  Constructor for the EmissionSpectrumModifier object
	 */
	public CmInvToNm() { }


	/**
	 *  Convert energy scale
	 *
	 *@param  energy  The energy double array
	 *@return         The converted energy array
	 */
	public double[] convertEnergyScale(double[] energy)
	{
		for (int i = 0; i < energy.length; i++)
		{
			energy[i] /= 1000.0;
		}
		return energy;
	}


	/**
	 *  Convert energy scale
	 *
	 *@param  energy  The energy P0D array
	 *@return         The converted energy array
	 */
	public P0D convertEnergyScale(P0D energy)
	{
		for (int i = 0; i < energy.size(); i++)
		{
			energy.set(i, 1000.0 / energy.get(i));
		}
		return energy;
	}


	/**
	 *  Convert energy scale
	 *
	 *@param  spectrum  The P1D spectrum
	 *@return           The converted energy spectrum
	 */
	public P1D convertEnergyScale(P1D spectrum)
	{
		int max = spectrum.size();
		P1D scaleSpec = new P1D("Scaled Spectrum");
		for (int i = 0; i < max; i++)
		{
			//spectrum.set(i, 1000.0 / spectrum.getX(i), spectrum.getY(i), 1000.0 / spectrum.getXleft(i), 1000.0 / spectrum.getXright(i), spectrum.getYupper(i), spectrum.getYlower(i));
			scaleSpec.add(1000.0 / spectrum.getX(i), spectrum.getY(i), 1000.0 / spectrum.getXleft(i), 1000.0 / spectrum.getXright(i), spectrum.getYupper(i), spectrum.getYlower(i));
		}
		return scaleSpec;
	}


	/**
	 *  Convert energy scale
	 *
	 *@param  spectrum  The IDataPointSet spectrum
	 *@return           The converted energy spectrum
	 */
	public IDataPointSet convertEnergyScale(IDataPointSet spectrum)
	{
		int max = spectrum.size();
		for (int i = 0; i < max; i++)
		{
			spectrum.point(i).coordinate(0).setValue(1000.0 / spectrum.point(i).coordinate(0).value());
			spectrum.point(i).coordinate(0).setErrorMinus(1000.0 / spectrum.point(i).coordinate(0).errorMinus());
			spectrum.point(i).coordinate(0).setErrorPlus(1000.0 / spectrum.point(i).coordinate(0).errorPlus());
		}
		return spectrum;
	}

}

